// pages/prescription-detail/prescription-detail.js
Page({
	data: {
		prescriptionId: '',
		patientName: '',
		doctorName: '',
		department: '',
		prescriptionDate: '',
		diagnosis: '',
		status: '',
		medicineList: [],
		instructionText: '',
		noticeList: []
	},

	onLoad(options) {
		console.log('处方详情页面加载')
		console.log('页面参数:', options)
		
		if (options.prescriptionId) {
			this.setData({
				prescriptionId: options.prescriptionId
			})
			this.loadPrescriptionDetail(options.prescriptionId)
		}
		
		if (options.patient) {
			this.setData({
				patientName: options.patient
			})
		}
	},

	// 加载处方详情
	loadPrescriptionDetail(prescriptionId) {
		// 根据处方ID获取详细信息
		const prescriptionDetails = this.getPrescriptionDetails(prescriptionId)
		
		this.setData({
			doctorName: prescriptionDetails.doctorName,
			department: prescriptionDetails.department,
			prescriptionDate: prescriptionDetails.date,
			diagnosis: prescriptionDetails.diagnosis,
			status: prescriptionDetails.status,
			medicineList: prescriptionDetails.medicineList,
			instructionText: prescriptionDetails.instructionText,
			noticeList: prescriptionDetails.noticeList
		})
	},

	// 获取处方详情数据
	getPrescriptionDetails(prescriptionId) {
		const prescriptionData = {
			'001': {
				doctorName: '张医生',
				department: '内科 - 呼吸内科',
				date: '2025-08-01',
				diagnosis: '上呼吸道感染',
				status: '已完成',
				medicineList: [
					{
						name: '阿莫西林胶囊',
						specification: '0.25g*24粒/盒',
						manufacturer: '华北制药股份有限公司',
						quantity: '2盒',
						usage: '口服',
						frequency: '每日3次',
						duration: '7天',
						price: 15.80
					},
					{
						name: '布洛芬缓释胶囊',
						specification: '0.3g*12粒/盒',
						manufacturer: '中美天津史克制药有限公司',
						quantity: '1盒',
						usage: '口服',
						frequency: '每日2次',
						duration: '3天',
						price: 12.50
					},
					{
						name: '复方甘草片',
						specification: '24片/盒',
						manufacturer: '哈药集团制药总厂',
						quantity: '2盒',
						usage: '含服',
						frequency: '每日3次',
						duration: '7天',
						price: 8.90
					}
				],
				instructionText: '请按时服药，多休息，多喝水。如有发热持续不退或症状加重，请及时就医。',
				noticeList: [
					'阿莫西林为抗生素，请按时服用，不可随意停药',
					'布洛芬饭后服用，避免空腹',
					'复方甘草片含服，不要咀嚼',
					'服药期间避免饮酒',
					'如有过敏反应请立即停药并就医'
				]
			},
			'002': {
				doctorName: '张医生',
				department: '内科 - 呼吸内科',
				date: '2025-07-15',
				diagnosis: '支气管炎',
				status: '待配药',
				medicineList: [
					{
						name: '头孢克肟分散片',
						specification: '0.1g*12片/盒',
						manufacturer: '齐鲁制药有限公司',
						quantity: '3盒',
						usage: '口服',
						frequency: '每日2次',
						duration: '10天',
						price: 28.60
					},
					{
						name: '氨溴特罗片',
						specification: '20片/盒',
						manufacturer: '勃林格殷格翰制药有限公司',
						quantity: '2盒',
						usage: '口服',
						frequency: '每日2次',
						duration: '10天',
						price: 45.80
					}
				],
				instructionText: '支气管炎需要规范治疗，请按时服药。注意保暖，避免受凉。',
				noticeList: [
					'头孢类抗生素请按时服用',
					'氨溴特罗片饭后服用',
					'避免吸烟和二手烟',
					'保持室内空气流通',
					'如有胸闷气短加重请及时就医'
				]
			},
			'003': {
				doctorName: '李医生',
				department: '内科 - 消化内科',
				date: '2025-08-02',
				diagnosis: '慢性胃炎',
				status: '已完成',
				medicineList: [
					{
						name: '奥美拉唑肠溶胶囊',
						specification: '20mg*14粒/盒',
						manufacturer: '阿斯利康制药有限公司',
						quantity: '2盒',
						usage: '口服',
						frequency: '每日1次',
						duration: '14天',
						price: 35.20
					},
					{
						name: '枸橼酸铋钾胶囊',
						specification: '0.3g*24粒/盒',
						manufacturer: '丽珠医药集团股份有限公司',
						quantity: '2盒',
						usage: '口服',
						frequency: '每日3次',
						duration: '14天',
						price: 18.90
					}
				],
				instructionText: '胃炎患者需注意饮食规律，避免辛辣刺激性食物。',
				noticeList: [
					'奥美拉唑空腹服用',
					'枸橼酸铋钾饭后服用',
					'避免饮酒和刺激性食物',
					'规律饮食，少食多餐',
					'如有黑便请立即就医'
				]
			},
			'005': {
				doctorName: '王医生',
				department: '内科 - 心血管内科',
				date: '2025-08-05',
				diagnosis: '高血压',
				status: '待配药',
				medicineList: [
					{
						name: '硝苯地平缓释片',
						specification: '30mg*7片/盒',
						manufacturer: '拜耳医药保健有限公司',
						quantity: '4盒',
						usage: '口服',
						frequency: '每日1次',
						duration: '28天',
						price: 42.50
					}
				],
				instructionText: '请按时服药，注意饮食调理。',
				noticeList: [
					'阿司匹林肠溶片饭后服用',
					'辛伐他汀片晚上服用',
					'定期监测血脂',
					'如有肌肉酸痛及时就医',
					'避免与葡萄柚汁同服'
				]
			},
			'014': {
        doctorName: '张医生',
        department: '内科 - 呼吸内科',
        date: '2025-08-06',
        diagnosis: '上呼吸道感染',
        status: '待配药',
        medicineList: [
          { name: '阿奇霉素片', specification: '250mg*6片/盒', manufacturer: '辉瑞制药有限公司', quantity: '1盒', usage: '口服', frequency: '每日1次', duration: '3天', price: 22.60 },
          { name: '氨溴索口服溶液', specification: '100ml/瓶', manufacturer: '先声药业', quantity: '1瓶', usage: '口服', frequency: '每日3次', duration: '5天', price: 16.50 }
        ],
        instructionText: '请按时用药，注意休息，多喝水。',
        noticeList: ['阿奇霉素与含钙食物间隔2小时', '如出现皮疹等不适请停药就医']
      },
      '007': {
        doctorName: '赵医生',
        department: '外科 - 骨科',
        date: '2025-08-03',
        diagnosis: '腰椎间盘突出',
        status: '已完成',
        medicineList: [
          { name: '洛索洛芬钠片', specification: '60mg*12片/盒', manufacturer: '第一三共制药', quantity: '1盒', usage: '口服', frequency: '每日2次', duration: '7天', price: 26.50 },
          { name: '甲钴胺片', specification: '0.5mg*20片/盒', manufacturer: '卫材制药', quantity: '1盒', usage: '口服', frequency: '每日3次', duration: '14天', price: 32.80 }
        ],
        instructionText: '避免久坐久站，按时服药，适度功能锻炼。',
        noticeList: ['非甾体消炎药饭后服用', '如有胃痛及时就医']
      },
      '008': {
        doctorName: '赵医生',
        department: '外科 - 骨科',
        date: '2025-07-18',
        diagnosis: '膝关节炎',
        status: '已完成',
        medicineList: [
          { name: '塞来昔布胶囊', specification: '200mg*6粒/盒', manufacturer: '辉瑞', quantity: '2盒', usage: '口服', frequency: '每日1-2次', duration: '7天', price: 29.90 },
          { name: '氨糖软骨素片', specification: '0.5g*30片/盒', manufacturer: '汤臣倍健', quantity: '1盒', usage: '口服', frequency: '每日2次', duration: '30天', price: 45.00 }
        ],
        instructionText: '注意保暖，避免剧烈运动。',
        noticeList: ['饭后服用更舒适', '如关节肿胀明显请复诊']
      },
      '010': {
        doctorName: '孙医生',
        department: '儿科 - 儿科门诊',
        date: '2025-08-06',
        diagnosis: '小儿感冒',
        status: '已完成',
        medicineList: [
          { name: '对乙酰氨基酚混悬液', specification: '100ml/瓶', manufacturer: '北京顺鑫', quantity: '1瓶', usage: '口服', frequency: '按体重计量', duration: '3天', price: 18.00 },
          { name: '氯雷他定糖浆', specification: '60ml/瓶', manufacturer: '先灵', quantity: '1瓶', usage: '口服', frequency: '每日1次', duration: '5天', price: 22.50 }
        ],
        instructionText: '多喝水，注意休息，按时用药。',
        noticeList: ['严格按医嘱按体重给药', '如持续发热请就诊']
      },
      '011': {
        doctorName: '孙医生',
        department: '儿科 - 儿科门诊',
        date: '2025-07-28',
        diagnosis: '小儿咳嗽',
        status: '已完成',
        medicineList: [
          { name: '氨溴索口服液', specification: '100ml/瓶', manufacturer: '先声药业', quantity: '1瓶', usage: '口服', frequency: '每日2-3次', duration: '5天', price: 16.50 },
          { name: '右美沙芬口服液', specification: '100ml/瓶', manufacturer: '健民', quantity: '1瓶', usage: '口服', frequency: '每日3次', duration: '5天', price: 15.80 }
        ],
        instructionText: '避免受凉，保持空气湿润。',
        noticeList: ['夜间咳嗽加重可复诊', '注意监测体温']
      },
      '013': {
        doctorName: '周医生',
        department: '皮肤科 - 皮肤科门诊',
        date: '2025-07-30',
        diagnosis: '荨麻疹',
        status: '已完成',
        medicineList: [
          { name: '盐酸西替利嗪片', specification: '10mg*6片/盒', manufacturer: 'UCB', quantity: '2盒', usage: '口服', frequency: '每日1次', duration: '7天', price: 18.90 }
        ],
        instructionText: '避免抓挠，远离过敏原。',
        noticeList: ['尽量避免海鲜、酒精等诱发食物']
      },
      '015': {
        doctorName: '刘医生',
        department: '内科 - 呼吸内科',
        date: '2025-08-08',
        diagnosis: '急性咽炎',
        status: '待配药',
        medicineList: [
          { name: '萘敏维滴剂', specification: '10ml/瓶', manufacturer: '国药集团', quantity: '1瓶', usage: '含服', frequency: '每日3次', duration: '5天', price: 19.80 },
          { name: '西地碘含片', specification: '24片/盒', manufacturer: '广州白云山', quantity: '1盒', usage: '含服', frequency: '每日3次', duration: '5天', price: 14.90 }
        ],
        instructionText: '避免辛辣刺激，注意口腔卫生。',
        noticeList: ['含片不可吞咽', '滴剂按滴数使用']
      },
      '016': {
        doctorName: '王医生',
        department: '内科 - 心血管内科',
        date: '2025-08-08',
        diagnosis: '冠心病随访',
        status: '待配药',
        medicineList: [
          { name: '阿司匹林肠溶片', specification: '100mg*30片/盒', manufacturer: '拜耳医药保健', quantity: '1盒', usage: '口服', frequency: '每日1次', duration: '30天', price: 23.50 },
          { name: '瑞舒伐他汀片', specification: '10mg*7片/盒', manufacturer: '阿斯利康', quantity: '4盒', usage: '口服', frequency: '每日1次', duration: '28天', price: 35.80 }
        ],
        instructionText: '坚持长期规范用药，定期复诊。',
        noticeList: ['服药期间避免饮酒', '如有胃部不适及时就医']
      },
      '017': {
        doctorName: '周医生',
        department: '皮肤科 - 皮肤科门诊',
        date: '2025-08-08',
        diagnosis: '皮炎',
        status: '待配药',
        medicineList: [
          { name: '地奈德乳膏', specification: '15g/支', manufacturer: '和黄药业', quantity: '1支', usage: '外用', frequency: '每日2次', duration: '10天', price: 21.50 },
          { name: '非索非那定片', specification: '60mg*10片/盒', manufacturer: '赛诺菲', quantity: '1盒', usage: '口服', frequency: '每日2次', duration: '7天', price: 29.90 }
        ],
        instructionText: '避免抓挠，外用药薄涂患处。',
        noticeList: ['外用药勿接触眼口', '口服药按时按量']
      },
			'009': {
				doctorName: '钱医生',
				department: '外科 - 普通外科',
				date: '2025-08-04',
				diagnosis: '甲状腺结节',
				status: '待配药',
				medicineList: [
					{
						name: '左甲状腺素钠片',
						specification: '50μg*30片/盒',
						manufacturer: '默克雪兰诺有限公司',
						quantity: '2盒',
						usage: '口服',
						frequency: '每日1次',
						duration: '30天',
						price: 25.60
					},
					{
						name: '硒酵母片',
						specification: '50μg*60片/盒',
						manufacturer: '北京同仁堂科技发展股份有限公司',
						quantity: '1盒',
						usage: '口服',
						frequency: '每日2次',
						duration: '30天',
						price: 38.90
					}
				],
				instructionText: '甲状腺结节需要定期复查，请按时服药，保持良好作息。',
				noticeList: [
					'左甲状腺素钠片空腹服用',
					'硒酵母片饭后服用',
					'定期复查甲状腺功能',
					'避免过度劳累',
					'保持心情舒畅，避免情绪波动'
				]
			},
			'012': {
				doctorName: '周医生',
				department: '皮肤科 - 皮肤科门诊',
				date: '2025-08-07',
				diagnosis: '湿疹',
				status: '待配药',
				medicineList: [
					{
						name: '糠酸莫米松乳膏',
						specification: '10g/支',
						manufacturer: '拜耳医药保健有限公司',
						quantity: '2支',
						usage: '外用',
						frequency: '每日2次',
						duration: '14天',
						price: 18.50
					},
					{
						name: '氯雷他定片',
						specification: '10mg*6片/盒',
						manufacturer: '先灵葆雅制药有限公司',
						quantity: '2盒',
						usage: '口服',
						frequency: '每日1次',
						duration: '7天',
						price: 12.80
					},
					{
						name: '维生素E软胶囊',
						specification: '100mg*30粒/盒',
						manufacturer: '汤臣倍健股份有限公司',
						quantity: '1盒',
						usage: '口服',
						frequency: '每日2次',
						duration: '14天',
						price: 22.40
					}
				],
				instructionText: '湿疹需要内外结合治疗，外用药物涂抹患处，口服药物缓解症状。',
				noticeList: [
					'糠酸莫米松乳膏不可长期使用',
					'氯雷他定片饭后服用',
					'避免搔抓患处',
					'保持皮肤清洁干燥',
					'避免接触过敏原'
				]
			}
		}

		return prescriptionData[prescriptionId] || {
			doctorName: '医生',
			department: '科室',
			date: '2025-08-08',
			diagnosis: '诊断',
			status: '已完成',
			medicineList: [],
			instructionText: '请按医嘱用药，如有不适请及时就医。',
			noticeList: [
				'请按时服药',
				'注意饮食调理',
				'如有不适请及时就医'
			]
		}
	},

	// 在线配药
	refillPrescription() {
		console.log('在线配药')
		wx.navigateTo({
			url: '/pages/online-refill/online-refill?patient=' + this.data.patientName + '&prescriptionId=' + this.data.prescriptionId
		})
	},

	// 下载处方
	downloadPrescription() {
		console.log('下载处方')
		wx.showToast({
			title: '处方下载功能',
			icon: 'none',
			duration: 2000
		})
	}
})
